package com.tn.service.homepage.impl;

import com.tn.controller.alarm.common.enums.TruckStatusEnum;
import com.tn.dao.homepage.ICommonPageDao;
import com.tn.service.homepage.CommonPageService;
import com.tn.controller.alarm.common.model.homepage.vo.WarningCarDataVO;
import com.tn.controller.alarm.common.model.statistics.vo.CurrentTruckLoadingStatisticsVO;
import com.tn.controller.alarm.common.model.statistics.vo.LoadCarStatisticVO;
import com.tn.controller.alarm.common.model.TextAndValueVO;
import com.tn.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @ClassName CommonServiceImpl
 * @Description TODO
 * @Author Yezhongzhu
 * @Date 2021/12/2 9:40
 * @Version v1.0
 **/
@Service
public class CommonPageServiceImpl implements CommonPageService {
    @Autowired
    private ICommonPageDao commonPageDao;

    @Override
    public CurrentTruckLoadingStatisticsVO getCurrentTruckLoadingStatistics() {
        commonPageDao.getNoTruckCount(TruckStatusEnum.ALREADY_IN.getStatus(),TruckStatusEnum.STOP_OUT.getStatus(),DateUtil.dateToString(new Date()));
        return CurrentTruckLoadingStatisticsVO.builder().allCount(9)
                .underwayCount(2).waitingCount(3).finishCount(4).build();
    }

    @Override
    public Integer getTruckLeaveCount() {
        return commonPageDao.getTruckLeaveCount(TruckStatusEnum.ALREADY_OUT.getStatus(), DateUtil.getTodayStart(new Date()));
    }

    @Override
    public List<TextAndValueVO<String, Integer>> getTruckWorkTimeStatistic() {
        List<TextAndValueVO<String, Integer>> andValueVOList = new ArrayList<>();
        TextAndValueVO<String, Integer> textAndValueVO = null;
        for(int i=0;i<=9;i++){
            textAndValueVO = new TextAndValueVO<>();
            textAndValueVO.setText("XA0000"+i);
            textAndValueVO.setValue(i+3);
            andValueVOList.add(textAndValueVO);
        }
        return andValueVOList;
    }

    @Override
    public LoadCarStatisticVO getLoadCarStatistic() {
        return LoadCarStatisticVO.builder().loadingCount(0).stopCount(0).build();
    }

    @Override
    public List<WarningCarDataVO> getWarnCarList(String type) {
        List<WarningCarDataVO> warningCarDataVOS = new ArrayList<>();
        WarningCarDataVO vo = null;
        for(int i=0;i<=9;i++){
            vo = new WarningCarDataVO();
            vo.setLicense("XA1111"+i);
            vo.setWarningDate(new Date());
            vo.setWarningMsg("偏离轨迹");
            warningCarDataVOS.add(vo);
        }
        return warningCarDataVOS;
    }

    @Override
    public List<TextAndValueVO<String, Float>> getAllGoodsTypeStatistic() {
        List<TextAndValueVO<String, Float>> andValueVOList = new ArrayList<>();
        TextAndValueVO<String, Float> textAndValueVO = null;
        for(int i=1;i<=9;i++){
            textAndValueVO = new TextAndValueVO<>();
            textAndValueVO.setText("test"+i);
            textAndValueVO.setValue(Float.valueOf(10+i));
            andValueVOList.add(textAndValueVO);
        }
        return andValueVOList;
    }
}
